package com.chen.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.common.Result;
import com.chen.mapper.FileMapper;
import com.chen.mapper.UserMapper;
import com.chen.pojo.Files;
import com.chen.service.Impl.FilesServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 文件下载
 *
 * @author chen
 * @date 2022/5/4 15:24
 */

@RestController
@RequestMapping("/download")
@Api(value = "DownLoadController", tags = "文件下载")
public class DownLoadController {

    @Resource
    private UserMapper userMapper;

    @Resource
    private FilesServiceImpl filesService;

    @Resource
    private FileMapper fileMapper;


    @GetMapping("/findPoints/{id}")
    public Result isEnableDownLoad(@PathVariable("id") int id) {


        return Result.success(filesService.findPoints(id));
    }
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String name ,
                           @RequestParam(defaultValue = "") String type ) {

        QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
        // 查询未删除的记录
        queryWrapper.eq("is_delete", false);
        queryWrapper.eq("enable",true);
        queryWrapper.orderByDesc("id");
        if (!"".equals(name)) {
            queryWrapper.like("name", name);

        }
        if (!"".equals(type)) {
            queryWrapper.like("type", type);

        }

        return Result.success(fileMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper));
    }


}
